import {defineStore} from "pinia";
import {getSysAllMenu, putSysMenu} from "@/api/menu";
import type {TMenuInfo} from "@/api/menu/type.ts";
import {ElMessage} from "element-plus";

type TState = {
    allMenuList:TMenuInfo[]
}

const useMenuStore = defineStore("Menu",{
    state():TState{
        return {
            allMenuList:[]
        }
    },
    actions:{
        // 调用获取全部菜单列表的数据
        async getSysAllMenuAsync(){
            const result = await getSysAllMenu();
            this.allMenuList = result.menuList;
        },
        async putSysMenuAsync(id:string,status:number){
            const {message} = await putSysMenu(id,status);
            ElMessage.success(message);
            this.getSysAllMenuAsync();
        }
    }
});
export default useMenuStore;